//app.js
const utils = require('/utils/util.js');
App({


    onLaunch: function () {
        var $this = this;



        // 展示本地存储能力
        // var logs = wx.getStorageSync('logs') || []
        // logs.unshift(Date.now())
        // wx.setStorageSync('logs', logs);
        $this.globalData.token = wx.getStorageSync("token");
        console.log($this.globalData.token);
        if ($this.globalData.token) {
            console.log("已经存在了");
            console.log($this.globalData.token);
            return !1;
        }
        console.log('不存在');

        wx.getSystemInfo({
            success: function (res) {

                console.log(res);

            }
        });


        // 登录
        wx.login({
            success: function (e) {
                console.log(e);
                console.log('获取code成功');
                utils.geturl({
                    "handler": "User",
                    "method": "login",
                    "param": '{"code":"' + e.code + '"}'
                }, function (res) {
                    console.log(res);
                    if(res.code==200){
                        wx.setStorageSync("token", res.data.obj.token);
                        $this.globalData.token = res.data.obj.token;
                    }else {
                        wx.showToast({
                            title: '服务器错误,请稍候再试',
                            icon: "none"
                        });
                    }
                });
            }
        })
    },
    globalData: {
        userInfo: null,
        userid: 0,
        token:''
    },

});